@extends('admin/index')
@section('name')

    <h1><span class="label label-default"> 资讯信息子分类列表  </span></h1>
    <hr>
    <a href="">返回上一级</a>

    <table class="table table-bordered  table-hover" id="tent">
        <tr id="ai">
            <th>ID</th>
            <th>父级pid</th>
            <th>name</th>
            <th>path</th>
            <th>display</th>
            <th>操作</th>
        </tr>
        @if(empty($res))

            <tr>
                <td colspan="6">当前没有子分类,请添加</td>
            </tr>
        @else
        @forelse($res as $list)
            <tr>
                <th scope="row">{{$list->id}}</th>
                <th>{{$list->pid}}</th>
                <th>{{$list->name}}</th>
                <th>{{$list->path}}</th>
                <th>
                    <a href="{{url('editstatic')}}/{{$list->id}}/{{$list->display}}/{{$list->pid}}">

                    @if(($list->display) == 1)
                        显示
                    @else
                         隐藏
                    @endif
                    </a>
                </th>
                <th>
                    {{--模态框--}}

          <button type="button" onclick="editcha({{$list->id}})" class="btn btn btn-info" data-toggle="modal" data-target="#myModal" id="bbb">
                        编辑子分类
                    </button>

                    <!-- Modal -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h1><span class="label label-default"> 子分类列表  </span></h1>
                                </div>
                                <div class="modal-body" style="marigin-leift:20px">
                  <form action="{{url('editclass')}}">

                                        <p>分类名: <input required type="text" name='name' placeholder='name' id="na" value=""></p>

                                        <p>Pid: <input type="text" name='pid' value="" readonly  id="pid"></p>
                                        <p>Path: <input type="text" name='path' value="" readonly id="path">
                                            <input type="hidden" name="id" id="nn" varlue="">

                                        </p>
                                        <p>Display:
                                            <label for="y"> <input  id='y' type="radio" name='display' value="1"> 显示 </label>
                                            <label for="n"> <input id='n' type="radio" name='display' value="2"> 隐藏 </label>


                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">退出</button>
                                    <button type="submit" class="btn btn-primary">保存</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    {{--end  motai--}}
                    <button class="btn btn-danger" id="but1" onclick="del({{$list->id}})">删除分类</button>

                </th>
            </tr>
        @empty
            <p>数据暂无</p>
        @endforelse
        @endif

    </table>

    {{$res->links()}}

<script>


    function del(a)
    {

        if (confirm('你确定要删除嘛')){


            var  data = a;
            $.ajax({
            type:'get',
            url:"{{url('delchild')}}/" + data,
            success:function(data){
                if (data == 1) {

                $('#but1').parent().parent().remove();
            }
            },
            error:function(){

                 alert('AJAX 发生错误');
            }
                })


        }else{

            alert('我就知道你点错了QAQ')
        }




    }



        function editcha(b)
        {
            var  data = b;

            $.ajax({
                type:'get',
                url:"{{url('ajaxclass')}}/" + data,

                success:function(data){
                    if(data){
                        $('#pid').attr("value",data[0]);
                        $('#path').attr("value",data[1]);
                        $('#nn').attr("value",data[2]);
                        $('#na').attr("value",data[3]);
                        console.log(data);
                        if (data[4]  == 1){
                            $('#n').attr("checked",'checked');
                        }else{
                            $('#y').attr("checked",'checked');
                        }

                    }
                },
                error:function(){

                    console.log('错误');
                }
            })

//        alert('11');

        }





</script>
    @endsection
